package com.nwu.custom_view;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.DecelerateInterpolator;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.activity.MainActivity;
import com.nwu.custom_view.qq_step_view.QQStepView;
import com.nwu.custom_view.qq_step_view.StepView;


/**
 * 组合Activity
 */
public class CombineActivity extends AppCompatActivity {

    private StepView stepView;

    private QQStepView qqStepView1;
    private QQStepView qqStepView2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /*setContentView(R.layout.activity_qq_step_view);

        stepView = findViewById(R.id.step_view);
        stepView.setMaxStep(10000);  // 设置最大值
        // 添加属性动画
        ValueAnimator valueAnimator = ObjectAnimator.ofInt(0, 8000);
        valueAnimator.setDuration(2000L);    // 动画持续时间
        valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int currentStep = (int) animation.getAnimatedValue();
                stepView.setCurrentStep(currentStep);
            }
        });
        valueAnimator.start();*/

        setContentView(R.layout.activity_my_linear_layout);

        // 第一个QQ计步器控件
        qqStepView1 = findViewById(R.id.qq_step_view1);
        qqStepView1.setMaxStep(10000);  // 设置最大值
        // 添加属性动画
        ValueAnimator valueAnimator = ObjectAnimator.ofInt(0, 6666);
        valueAnimator.setDuration(2500L);    // 动画持续时间
        //valueAnimator.setInterpolator(new DecelerateInterpolator());
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int currentStep = (int) animation.getAnimatedValue();
                qqStepView1.setCurrentStep(currentStep);
            }
        });
        valueAnimator.start();
        // 添加文字扫描效果动画
        ValueAnimator scanAnimator = ValueAnimator.ofFloat(0f, 1f);
        scanAnimator.setDuration(2000L); // 动画持续时间
        scanAnimator.setRepeatCount(ValueAnimator.INFINITE); // 无限循环
        scanAnimator.setRepeatMode(ValueAnimator.RESTART); // 重新开始
        scanAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float fraction = (float) animation.getAnimatedValue();
                qqStepView1.updateSweepShader(fraction);
            }
        });
        scanAnimator.start();

        // 第二个QQ计步器控件
        qqStepView2 = findViewById(R.id.qq_step_view2);
        qqStepView2.setMaxStep(10000);  // 设置最大值
        // 添加属性动画
        ValueAnimator valueAnimator2 = ObjectAnimator.ofInt(0, 10000);
        valueAnimator2.setDuration(2500L);    // 动画持续时间
        valueAnimator2.setInterpolator(new DecelerateInterpolator());
        valueAnimator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int currentStep = (int) animation.getAnimatedValue();
                qqStepView2.setCurrentStep(currentStep);
            }
        });
        valueAnimator2.start();
        // 添加文字扫描效果动画
        ValueAnimator scanAnimator2 = ValueAnimator.ofFloat(0f, 1f);
        scanAnimator2.setDuration(2000L); // 动画持续时间
        scanAnimator2.setRepeatCount(ValueAnimator.INFINITE); // 无限循环
        scanAnimator2.setRepeatMode(ValueAnimator.RESTART); // 重新开始
        scanAnimator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float fraction = (float) animation.getAnimatedValue();
                qqStepView2.updateSweepShader(fraction);
            }
        });
        scanAnimator2.start();

        //startActivity(new Intent(CombineActivity.this, MainActivity.class));
    }
}
